import React from 'react';

import {
    Dialog
} from './../../components';

import Content from './content';

export type Type = 'subscribe' | 'consumable';

interface Options {
    type: Type,
    planId: string
}

const buy = (opts:Options):Promise<any> => (
    new Promise((resolve, reject) => {
        const {
            type,
            planId
        } = opts || {};
        const content = (
            <Content
                type={type}
                planId={planId}
                onError={reject}
                onSuccess={resolve}
            />
        )
        const _props:any = {
            direction:`none`
        }
        Dialog.show(content,_props);
    })
)

export default class Pay {
    static buy = buy
}